
<?php 
	$dialogId = "DialogEditAnswer";
	$messageErrorId = "messageErrorId";
?>

<div class="box_mid" id="<?= $dialogId?>" title="Edit answer">
	<?php echo $this->Session->flash(); ?>
	<?php echo "<div id='$messageErrorId'></div>";?>
	<div class="box_mid_content">
		<div class="box_mid_content_top">
		</div>
		<div class="box_mid_content_mid">
		<?php $idCkeditor = 'Content' ;?>
		<?= $this->Form->create('Answer')?>
			<div class="info">
				<?= $this->Form->input('correct',array('id' => 'correct', 'checked' => $answer['Answer']['correct']))?>
			</div>
			<?= $this->Form->input('content', array('id'=>$idCkeditor, 'value'=>$answer['Answer']['content']));?>
			<?= $this->CKEditor->load($idCkeditor) ?>
			<?= $this->Form->end(); ?>
		</div>
	</div>
</div>

<script type="text/javascript">

	function ShowQuestionById(div_id) {
		$.ajax({
			async:true,
			url: "../questions/ShowQuestion/"+<?= $answer['Answer']['question_id']?>,
			beforeSend:function(request){

			},
			complete:function(request){
				html = '<li>'+request.responseText+'</li>';
				$('#'+div_id).append(html);
			}  
		});
	}

	$(function() {
		
		$("#<?= $dialogId ?>").dialog({
			autoOpen: true,
			modal: true,
			bgiframe: true,
			height: 600,
			width: 1000,
			title: "Edit answer" ,
			show: { effect: 'drop', direction: "up" },
			hide: { effect: 'drop', direction: "down" },
			buttons: [
						{
						    text: "Save",
						    click: function(){
						    	var answerContent_data = CKEDITOR.instances["<?= $idCkeditor?>"].getData();			    	
								$.ajax({
									url: "../answers/edit/" + <?= $answer['Answer']['id'] ?>,
									data: {
										'id': <?= $answer['Answer']['id'] ?>,
										'correct': $("#correct").is(':checked')?1:0,
										'content': answerContent_data
									},
									beforeSend:function(request){

									},
									complete:function(request){
										$("#<?= $dialogId ?>").dialog("close");
										$('#MainContent').html(request.responseText);
									}  
								});
						    }
						 },
						{
							text: "Close",
							click: function(){
								$(this).dialog("close");
							}
						}
					],
				close: function(){
					$('#<?= $dialogId ?>').remove();
					$('.ui-effects-wrapper').remove();
				}
		});
	});

</script>